<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
	function myPopup2() 
	{
		
		window.open( 'studgrades.php?subj=', "myWindow", 
		"status = 1, height = 300, width = 300, resizable = 0" )
	}

</script>
</head>

<body>
<?php 

?>
<br />
<table width="200" border="1">
  <tr>
    <td>&nbsp;</td>
    <td colspan="6">&nbsp;</td>
  </tr>
  <tr>
    <td rowspan="3">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td rowspan="2">&nbsp;</td>
    <td rowspan="2">&nbsp;</td>
    <td rowspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>















<?php
	//Includes
	include("include/class.connection.php");
	include("include/functions.php");
	
	//Stat session
	session_start();
	
	if(isset($_SESSION['proff_id']))
	{
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h1>КЛАС <?php echo(" ".convertToRoman($_GET['class'])."-".$_GET['subCl']); ?></h1>
<table border="1">
<?php
	//Getting the names of grades in coresponding class
	$sql4="SELECT subjects.* FROM subjects, class, proffclass, profsubject WHERE subjects.subject_id=profsubject.subject_id AND profsubject.proffesor_id=proffclass.proffesor_id AND proffclass.class_id=class.class_id AND class.class_id={$_GET['classID']} ORDER BY name";
	$result4=mysql_query($sql4) or die("Can not select the subjects for coreponding class ".mysql_error());
	echo("<tr>");
		echo("<td>&nbsp;</td>");
	while($subjName=mysql_fetch_array($result4))
	{
		echo("<td>{$subjName['name']}</td>");
	}
	echo("</tr>");
	
	
	//Selecting the student of coreponding class
	$sql="SELECT students.* FROM students WHERE students.class_id={$_GET['classID']} ORDER BY name";
	$result=mysql_query($sql) or die("Can not select students of this class ".mysql_error());
		$redBr=1;
		while($stud=mysql_fetch_array($result))
		{
			
			
			
			//Selecting the grades of this class
			$sql2="SELECT subjects.* FROM subjects, class, proffclass, profsubject WHERE subjects.subject_id=profsubject.subject_id AND profsubject.proffesor_id=proffclass.proffesor_id AND proffclass.class_id=class.class_id AND class.class_id={$_GET['classID']} ORDER BY name";
			$result2=mysql_query($sql2) or die("Can not select the subjects for coreponding class ".mysql_error());
			
			
			//Counting nuber od rows
			$vkupnoS=0;
			while($subj1=mysql_fetch_array($result2))
			{
				$sql5="SELECT COUNT(grade_id) AS br FROM grades WHERE student_id={$stud['student_id']} AND subject_id={$subj1['subject_id']}";
				$result5=mysql_query($sql5) or die("Can not select grades for this student ".mysql_error());
				$vkupnoS=mysql_fetch_array($result5);
				$vkupnoS=$vkupnoS['br']+1;
				$vkupno=$vkupnoS-1;
				
			}
			//echo("<h1>{$vkupnoS}</h1>");
			echo("<tr>");
			echo("<table border=1>");
					echo("<tr>");
						echo("<td rowspan={$vkupnoS} ><b>".$redBr.". ".$stud['name']."</b></td>");//rowspan
						echo("<td>Оценка</td>");
						echo("<td>Опис</td>");
						echo("<td>Пол</td>");
						echo("<td>I</td>");
						echo("<td>II</td>");
						echo("<td>Кон</td>");
					echo("</tr>");
			
			while($subj=mysql_fetch_array($result2))
			{
				//echo("<td>");
				//echo("<br /><font color=#000066 >&nbsp;&nbsp;&nbsp;  ".$subj['name']."</font><br/>");
				//Getting the gaades for this student
				$sql3="SELECT * FROM grades WHERE student_id={$stud['student_id']} AND subject_id={$subj['subject_id']}";
				$result3=mysql_query($sql3) or die("Can not select grades for this student ".mysql_error());
				$br=1;
				while($grade=mysql_fetch_array($result3))
				{
					echo("<tr>");
						echo("<td>{$grade['ocenka']}</td>");
						echo("<td>{$grade['description']}</td>");
						echo("<td>{$grade['semester']}</td>");
						if($br==1)
						{
							echo("<td rowspan=".$vkupno.">0</td>");
							echo("<td rowspan=".$vkupno.">0</td>");
							echo("<td rowspan=".$vkupno.">0</td>");	
						}
						$br++;
					//echo("&nbsp;&nbsp&nbsp;&nbsp&nbsp;".$grade['ocenka']." ".$grade['description']." ".$grade['semester']." || ");
					echo("</tr>");
				echo("</table>");
					
				}
				//echo("</td>");
			}
			//echo("</tr>");
			$redBr++;	
			//echo("<br/>");
		}
?>
</table>


</body>
<?php	
	}//end if (where checks if the proffesor is loged in )
?>
</html>